﻿using KELT.KELTObjects.ViewportObjectModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;

namespace KELT.Animation.ParticleEffect
{

    public class ParticleRotateAnimation : IAnimation
    {
        private DoubleAnimation cardYAnimation;

        private Rotation3DAnimation rotateAniamtion1;
        private Rotation3DAnimation rotateAniamtion2;
        private Rotation3DAnimation rotateAniamtion3;
        int distance = 50;

        public ParticleRotateAnimation()
        {
            cardYAnimation = new DoubleAnimation();
            rotateAniamtion1 = new Rotation3DAnimation();
            rotateAniamtion2 = new Rotation3DAnimation();
            rotateAniamtion3 = new Rotation3DAnimation();

        }
        public override void SetAnimation(Storyboard myStoryboard, ViewportObj obj)
        {
            animationName = "파티클_회전";
            Random rand = new Random();
            distance = 50;

            cardYAnimation.AccelerationRatio = 0.5;
            cardYAnimation.Duration = new Duration(TimeSpan.FromSeconds(endTime - startTime));
            cardYAnimation.BeginTime = TimeSpan.FromSeconds(startTime);

            cardYAnimation.From = obj.getPosition().Y + distance;
            //cardYAnimation.To = obj.getPosition().Y;
            Storyboard.SetTargetProperty(cardYAnimation, new PropertyPath(TranslateTransform3D.OffsetYProperty));

            Storyboard.SetTargetName(cardYAnimation, AnimationInfo.ANIMATION_TRANSLATE + obj.getIndexNumber());
            myStoryboard.Children.Add(cardYAnimation);





            Vector3D vector3D = new Vector3D(0, 0, 1);

            //회전애니메이션설정
            rotateAniamtion1.Duration = TimeSpan.FromSeconds((endTime - startTime) / 3);
            rotateAniamtion1.BeginTime = TimeSpan.FromSeconds(startTime + ((endTime - startTime) / 3));

            rotateAniamtion1.From = new AxisAngleRotation3D(vector3D, 0);
            rotateAniamtion1.By = new AxisAngleRotation3D(vector3D, 120);


            Storyboard.SetTargetName(rotateAniamtion1, AnimationInfo.ANIMATION_ROTATE + obj.getIndexNumber());
            Storyboard.SetTargetProperty(rotateAniamtion1, new PropertyPath(RotateTransform3D.RotationProperty));
            myStoryboard.Children.Add(rotateAniamtion1);



            //회전애니메이션설정
            rotateAniamtion2.Duration = TimeSpan.FromSeconds((endTime - startTime) / 3);
            rotateAniamtion2.BeginTime = TimeSpan.FromSeconds(startTime + ((endTime - startTime) / 3 * 2));

            rotateAniamtion2.From = new AxisAngleRotation3D(vector3D, 120);
            rotateAniamtion2.To = new AxisAngleRotation3D(vector3D, 240);


            Storyboard.SetTargetName(rotateAniamtion2, AnimationInfo.ANIMATION_ROTATE + obj.getIndexNumber());
            Storyboard.SetTargetProperty(rotateAniamtion2, new PropertyPath(RotateTransform3D.RotationProperty));
            myStoryboard.Children.Add(rotateAniamtion2);


            //회전애니메이션설정
            rotateAniamtion3.Duration = TimeSpan.FromSeconds((endTime - startTime) / 3);
            rotateAniamtion3.BeginTime = TimeSpan.FromSeconds(startTime + (endTime - startTime));

            rotateAniamtion3.From = new AxisAngleRotation3D(vector3D, 240);
            rotateAniamtion3.To = new AxisAngleRotation3D(vector3D, 360);


            Storyboard.SetTargetName(rotateAniamtion3, AnimationInfo.ANIMATION_ROTATE + obj.getIndexNumber());
            Storyboard.SetTargetProperty(rotateAniamtion3, new PropertyPath(RotateTransform3D.RotationProperty));
            myStoryboard.Children.Add(rotateAniamtion3);
        }



        public override  void deleteAnimation(Storyboard myStoryboard)
        {
            myStoryboard.Children.Remove(cardYAnimation);
            myStoryboard.Children.Remove(rotateAniamtion1);
            myStoryboard.Children.Remove(rotateAniamtion2);
            myStoryboard.Children.Remove(rotateAniamtion3);
        }
        public override  void changeAnimation(Storyboard myStoryboard)
        {
        }
    }
}
